package com.newcapec.servlet;

import com.google.gson.Gson;
import com.newcapec.bean.UserEntity;
import com.newcapec.dao.SysUserDao;
import com.newcapec.dao.impl.SysUserDaoImpl;
import com.newcapec.service.SysUserService;
import com.newcapec.service.impl.SysUserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description:通过id获取用户信息
 * @Author:yangshupeng
 * @Date: 2022/3/17 21:19
 * @Version:1.0
 */
@WebServlet("/getUser")
public class GetUserByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");*/

        //获取要删除的id
        String id = req.getParameter("id");
        SysUserService sysUserService = new SysUserServiceImpl();

        if (id != null){
            UserEntity userEntity = sysUserService.queryUserById(id);


            Gson gson = new Gson();
            resp.getWriter().write(gson.toJson(userEntity));
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
